package com.nny.demo141;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

import static com.nny.Class.forName;

public class DeleteDemo {
    private static final String URL = "jdbc:mysql://localhost:3306/test";
    private static final String DB_USERNAME = "root";
    private static final String DB_PASSWORD = "root";
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection(URL, DB_USERNAME, DB_PASSWORD);
        String  sql = "delete from userdb where id=?";
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
         Scanner scanner = new Scanner(System.in);
         System.out.println("请输入要删除的id");
         int id = scanner.nextInt();
         preparedStatement.setInt(1,id);
         int i  = preparedStatement.executeUpdate();
         if (i>0){
             System.out.println("删除成功");
         }else {
             System.out.println("删除失败");
         }
            }
    }
